<h2 mat-dialog-title>{{data ? '编辑宿舍' : '新增宿舍'}}</h2>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
  <div mat-dialog-content>
    <mat-form-field appearance="outline" class="form-field">
      <mat-label>房间号</mat-label>
      <input matInput formControlName="room_number" placeholder="请输入房间号">
      <mat-error *ngIf="form.get('room_number')?.errors?.['required']">房间号不能为空</mat-error>
    </mat-form-field>
    
    <mat-form-field appearance="outline" class="form-field">
      <mat-label>楼栋</mat-label>
      <input matInput formControlName="building" placeholder="请输入楼栋">
      <mat-error *ngIf="form.get('building')?.errors?.['required']">楼栋不能为空</mat-error>
    </mat-form-field>

    <mat-form-field appearance="outline" class="form-field">
      <mat-label>楼层</mat-label>
      <input matInput type="number" formControlName="floor" placeholder="请输入楼层">
      <mat-error *ngIf="form.get('floor')?.errors?.['required']">楼层不能为空</mat-error>
      <mat-error *ngIf="form.get('floor')?.errors?.['min']">楼层必须大于0</mat-error>
    </mat-form-field>

    <mat-form-field appearance="outline" class="form-field">
      <mat-label>容量</mat-label>
      <input matInput type="number" formControlName="capacity" placeholder="请输入容量">
      <mat-error *ngIf="form.get('capacity')?.errors?.['required']">容量不能为空</mat-error>
      <mat-error *ngIf="form.get('capacity')?.errors?.['min']">容量必须大于0</mat-error>
    </mat-form-field>

    <mat-form-field appearance="outline" class="form-field">
      <mat-label>已住人数</mat-label>
      <input matInput type="number" formControlName="occupied" placeholder="请输入已住人数">
      <mat-error *ngIf="form.get('occupied')?.errors?.['required']">已住人数不能为空</mat-error>
      <mat-error *ngIf="form.get('occupied')?.errors?.['min']">已住人数不能小于0</mat-error>
      <mat-error *ngIf="form.get('occupied')?.errors?.['max']">已住人数不能超过容量</mat-error>
    </mat-form-field>

    <mat-form-field appearance="outline" class="form-field">
      <mat-label>状态</mat-label>
      <mat-select formControlName="status">
        <mat-option value="可用">可用</mat-option>
        <mat-option value="维修中">维修中</mat-option>
        <mat-option value="已满">已满</mat-option>
      </mat-select>
      <mat-error *ngIf="form.get('status')?.errors?.['required']">状态不能为空</mat-error>
    </mat-form-field>

    <mat-form-field appearance="outline" class="form-field">
      <mat-label>描述</mat-label>
      <textarea matInput formControlName="description" placeholder="请输入描述" rows="3"></textarea>
    </mat-form-field>
  </div>

  <div mat-dialog-actions align="end">
    <button mat-button type="button" (click)="onCancel()">取消</button>
    <button mat-raised-button color="primary" type="submit" [disabled]="form.invalid">确定</button>
  </div>
</form>